/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function(x) {
  if (typeof x == 'number') {
    if (x < 10 && x >= 0) return true;
    x = x + '';
    for (let i = 0; i < x.length / 2; i++) {
      if (x[i] != x[x.length - 1 - i]) return false;
    }
    return true;
  } else {
    return false;
  }
};

// 最优代码。通过数字的处理来判读
/**
 * @param {number} x
 * @return {boolean}
 */
const isPalindrome2 = function(x) {
  if (x < 0) {
    return false;
  }
  let origin = x;
  let palindrome = 0,
    digit = 0;
  while (origin !== 0) {
    digit = origin % 10;
    palindrome = digit + palindrome * 10;
    origin = (origin - digit) / 10;
    if (origin === 0) {
      break;
    }
  }
  return palindrome === x;
};

console.log(isPalindrome(11))